* Regressions for bills and laws with varying controls.

clear all
set more off
set seed 8675309
set matsize 11000

include "bill-analysis/bill_setup.do"

// Tables 2, 4, and C1 (columns 3 and 7 of Tables 2 and C1 in reg_sessid.do)
foreach dv of varlist `billdv' `lawdv' {

    eststo clear
    loc m = 1

    foreach iv of varlist L.`shoot' L.`fatal' {

        xtpoisson `dv' `iv' `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "No"
        qui estadd local trnd = "No"
        eststo m`m' , title("State FE")
        loc m = `m' + 1

        xtpoisson `dv' `iv' i.year `rng', `opt'
        matrix A = (0, 0, _b[`iv'], _se[`iv'])
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("State/Year FE")
        loc m = `m' + 1

        xtpoisson `dv' `iv' `gov' i.year `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("Inst Ctrl")
        loc m = `m' + 1

        xtpoisson `dv' `iv' `politics' `gov' i.year `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("Politics")
        loc m = `m' + 1

        xtpoisson `dv' `iv' `politics' `gov' i.year c.year#i.fips `rng', `opt'
        matrix A = A \ (1, 0, _b[`iv'], _se[`iv'])
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "Yes"
        eststo m`m' , title("Trends")
        loc m = `m' + 1

        xtpoisson `dv' `iv' `politics' `gov' `demo' i.year c.year#i.fips `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "Yes"
        eststo m`m' , title("Trends Demo")
        loc m = `m' + 1
        di "% Effect of `iv' on `dv': ", 100 * (exp(_b[`iv'] - 0.5 * _se[`iv']^2) - 1)
    }

    // interaction of politics and shooting dummy
    foreach v in shoot fatal {

        xtpoisson `dv' `v'X???leg `politics' `gov' i.year `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("X Pol Inst Ctrl")
        loc m = `m' + 1

        xtpoisson `dv' `v'X???leg `politics' `gov' i.year c.year#i.fips `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "Yes"
        eststo m`m' , title("X Pol Trends")
        loc m = `m' + 1

        xtpoisson `dv' `v'X???leg `politics' `gov' `demo' i.year c.year#i.fips `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "Yes"
        eststo m`m' , title("X Pol Trends Demo")
        loc m = `m' + 1
        di "% Effect of `v'Xrepleg on `dv': ", /*
            */ 100 * (exp(_b[`v'Xrepleg] - 0.5 * _se[`v'Xrepleg]^2) - 1)
        di "% Effect of `v'Xdemleg on `dv': ", /*
            */ 100 * (exp(_b[`v'Xdemleg] - 0.5 * _se[`v'Xdemleg]^2) - 1)
        lincom `v'Xrepleg - `v'Xdemleg
    }

    writemodel using "`out'/`dv'", ext(csv) order(L.`shoot' L.`fatal' /*
        */ shootX* fatalX* 1.had_reg_session 1.biennium `politics')
}


// loosening and tightening (Table 5)

foreach dv of varlist laws_tighten laws_loosen {

    eststo clear
    loc m = 1

    foreach v in shoot fatal {
        xtpoisson `dv' L.``v'' `politics' `gov' i.year `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("Inst Ctrl")
        loc m = `m' + 1

        xtpoisson `dv' L.``v'' `politics' `gov' `demo' i.year `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("Demo")
        loc m = `m' + 1

        xtpoisson `dv' `v'X???leg `politics' `gov' i.year `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("X Pol Inst Ctrl")
        loc m = `m' + 1

        xtpoisson `dv' `v'X???leg `politics' `gov' `demo' i.year `rng', `opt'
        qui estadd local sfix = "Yes"
        qui estadd local yfix = "Yes"
        qui estadd local trnd = "No"
        eststo m`m' , title("X Pol Demo")
        loc m = `m' + 1
        di "% Effect of `v'Xrepleg on `dv': ", /*
            */ 100 * (exp(_b[`v'Xrepleg] - 0.5 * _se[`v'Xrepleg]^2) - 1)
        di "% Effect of `v'Xdemleg on `dv': ", /*
            */ 100 * (exp(_b[`v'Xdemleg] - 0.5 * _se[`v'Xdemleg]^2) - 1)
    }

    writemodel using "`out'/`dv'", ext(csv) order(L.`shoot' L.`fatal' /*
        */ shootX* fatalX* `politics' 1.had_reg_session 1.biennium)
}

// news coverage and shootings (Table 6)

eststo clear
loc m = 1

xtpoisson `billdv' L.news L.`shoot' i.year `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "No"
eststo m`m' , title("State/Year FE")
loc m = `m' + 1

xtpoisson `billdv' L.news L.`shoot' `gov' i.year `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "No"
eststo m`m' , title("Inst Ctrl")
loc m = `m' + 1

xtpoisson `billdv' L.news L.`shoot' `politics' `gov' i.year `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "No"
eststo m`m' , title("Politics")
loc m = `m' + 1

xtpoisson `billdv' L.news L.`shoot' `politics' `gov' i.year c.year#i.fips `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "Yes"
eststo m`m' , title("Trends")
loc m = `m' + 1

xtpoisson `billdv' L.news L.`shoot' `politics' `gov' `demo' i.year c.year#i.fips `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "Yes"
eststo m`m' , title("Trends Demo")
loc m = `m' + 1
di "% Effect of news on bills: ", 100 * (exp(_b[L.news] - 0.5 * _se[L.news]^2) - 1)

writemodel using "`out'/news", ext(csv) /*
    */ order(L.news L.`shoot' `politics' 1.had_reg_session 1.biennium)


// compare mass shootings with murder (Table 3)

loc iv "L.pc_`fatal' L.`murder'"

eststo clear

// institutional controls
xtpoisson `billdv' `iv' `gov' i.year `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "No"
eststo m`m', title("Inst Ctrl")
loc m = `m' + 1

// add political controls
xtpoisson `billdv' `iv' `gov' `politics' i.year `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "No"
eststo m`m', title("Politics")
loc m = `m' + 1

// add state-specific trends
xtpoisson `billdv' `iv' `gov' `politics' i.year i.fips#c.year `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "Yes"
eststo m`m', title("Trends")
loc m = `m' + 1

// add demographic controls
xtpoisson `billdv' `iv' `gov' `politics' `demo' i.year i.fips#c.year `rng', `opt'
qui estadd local sfix = "Yes"
qui estadd local yfix = "Yes"
qui estadd local trnd = "Yes"
eststo m`m', title("Trends Demo")
loc m = `m' + 1

// calculate murder equivalence
nlcom _b[L.pc_`fatal'] / _b[L.`murder']
matrix equiv = r(b)
matrix se_equiv = r(V)
loc equiv = round(equiv[1, 1], 0.001)
loc se_equiv = round(sqrt(se_equiv[1, 1]), 0.001)
di as result "`equiv' (`se_equiv') murders equals 1 mass shooting fatality"

writemodel using "`out'/murder_bills", ext(csv) drop(*.year) order(`iv')


// shootings in neighboring states (Appendix B)

include "bill-analysis/neighbor_vars.do"

loc controls = "`politics' `gov' `demo' i.year i.fips#c.year"
foreach dv of varlist `billdv' `lawdv' {
    include "bill-analysis/neighbor_effect.do"
}

loc controls = "`politics' `gov' `demo' i.year"
foreach dv of varlist laws_tighten laws_loosen {
    include "bill-analysis/neighbor_effect.do"
}


// control for gun ownership using share of suicides with a gun (Appendix I)

loc controls = "`politics' `gov' `demo' i.year"
include "bill-analysis/cook.do"


// placebo regressions
cap confirm file "`out'/placebo_main_effects.dta"
if _rc {
    loc placebo_runs = 1000
    loc placebo_dvs "`billdv' `lawdv' laws_tighten laws_loosen"
    loc controls = "`politics' `gov' `demo' i.year"
    include "bill-analysis/placebo.do"
    // add trends
    loc placebo_dvs "`billdv' `lawdv'"
    loc controls = "`politics' `gov' `demo' i.year i.fips#c.year"
    loc out = "`out'/time-trend"
    include "bill-analysis/placebo.do"
}

exit
// vim: foldmethod=indent
